package com.example.smarthomeyzy.activity;

import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.AppCompatImageView;
import androidx.appcompat.widget.AppCompatTextView;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.TextView;

import com.example.smarthomeyzy.R;

public class MainActivity extends AppCompatActivity {

    private static final String TAG = "MainActivity";

    CheckBox read, run , cai;
    String v_read="";
    String v_run="";
    String v_cai="";
    TextView show;

    private AppCompatTextView come;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        come = findViewById(R.id.come);

        come.setOnClickListener(view -> {
            Intent intent = new Intent(MainActivity.this, DemoActivity.class);
            startActivityForResult(intent, 1);
        });

        Intent intent = getIntent();
        String t_name= intent.getStringExtra("name");
        int t_age = intent.getIntExtra("age",0);
        System.out.println("接收到了数据="+t_name+" "+t_age);
        Log.d(TAG, "onCreate: "+"接收到了数据="+t_name+" "+t_age);

        initView();
        read.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                if(b)
                    v_read="读书";
                else
                    v_read="";
                show.setText("你选择了："+v_read+" "+v_run+" "+v_cai);
            }
        });
        cai.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                if(b)
                    v_cai="做菜";
                else
                    v_cai="";
                show.setText("你选择了："+v_read+" "+v_run+" "+v_cai);
            }
        });
        run.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean
                    b) {
                if(b)
                    v_run="跑步";
                else
                    v_run="";
                show.setText("你选择了："+v_read+" "+v_run+" "+v_cai);
            }
        });
    }
    private void initView() {
        read =findViewById(R.id.read);
        run=findViewById(R.id.run);
        cai=findViewById(R.id.cai);
        show = findViewById(R.id.show);
    }
    public void returnval(View v)
    {
        Intent intent = new Intent();
        intent.putExtra("myname","hhahahahah");
        setResult(210,intent);
        finish();
    }
}